package be.fomp.jeve.model.data.standard.conquerablestationlist;

import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.List;

import org.jdom.Document;
import org.jdom.Element;

import be.fomp.jeve.core.exceptions.JEveException;
import be.fomp.jeve.model.data.AbstractResultImpl;
import be.fomp.jeve.model.data.standard.ConquerableStationList;

public final class ConquerableStationListImpl extends AbstractResultImpl implements	ConquerableStationList {
	static final long serialVersionUID = 1L;
	
	private List<Outpost> outposts = new ArrayList<Outpost>();

	@SuppressWarnings("unchecked")
	public ConquerableStationListImpl(Document xmlDocument) throws JEveException {
		super(xmlDocument);

		Element root = xmlDocument.getRootElement();

		List<Element> resultSet = root.getChild("result").getChild("rowset").getChildren();
		for (Element outpostElement : resultSet) {
			Outpost outpost = new OutpostImpl(outpostElement);
			this.outposts.add(outpost);
		}
	}

	public List<Outpost> getOutposts() {
		return this.outposts;
	}

	public void writeObject(ObjectOutputStream os) {
		try {
			os.defaultWriteObject();
			os.writeObject(this.outposts);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@SuppressWarnings("unchecked")
	public void readObject(ObjectInputStream is) {
		try {
			is.defaultReadObject();
			this.outposts = ((List<Outpost>) is.readObject());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
